package com.example.bighomework.adapter;


import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.List;

public class ViewPagerAdapter extends FragmentStateAdapter {
    String titleArr[];
    List<Fragment> fragmentList;

    public ViewPagerAdapter(@NonNull FragmentActivity fragmentActivity,
                            List<Fragment> list,String[] titleArr) {
        super(fragmentActivity);
        fragmentList = list;
        this.titleArr = titleArr;
    }

//  页面位置 数量 标题
    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getItemCount() {
        return fragmentList != null ? fragmentList.size() : 0;
    }
    public CharSequence getTitle(int position) {
        return titleArr[position];
    }
}
